//
//  ALMainTabBarController.swift
//  ALSinaWeiBoSwift
//
//  Created by 柴瑞军 on 16/4/8.
//  Copyright © 2016年 myCompany. All rights reserved.
//

import UIKit
//快速打开官方文档:command+shift+0
class ALMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
//        着重考虑什么时候使用kvc   当属性是只读的时候,,即是get的时候
//        uitabbar属性是只读的,所以只能通过kvc进行赋值
        
        
        
//        自定义tabbar
        let ALTabBar = ALTabBarView()
        
        
        //实现闭包中的方法
        ALTabBar.composeClosure = {
         ()->Void in
            print("点击了加号按钮")
            
            //要跳转的控制器
            let composeVc = ALComposeControler()
            
            let nav = UINavigationController(rootViewController: composeVc)
            
           self.presentViewController(nav, animated: true, completion: nil)
        }
        
        setValue(ALTabBar, forKey: "tabBar")

        setupChildViewControllers()
    }
    
    private func setupChildViewControllers(){
        setupChildViewController(ALHomeTableViewController(), imageNamed:"tabbar_home", title: "首页")
        setupChildViewController(ALMessageTableViewController(), imageNamed:"tabbar_message_center", title: "消息")
        setupChildViewController(ALDiscoverTableViewController(), imageNamed:"tabbar_discover", title: "发现")
        setupChildViewController(ALProfileTableViewController(), imageNamed:"tabbar_profile", title: "我")

    }
    func setupChildViewController(controller: UIViewController ,imageNamed:String,title:String) {
        
        
        controller.tabBarItem.image = UIImage.init(named: imageNamed)
        controller.tabBarItem.selectedImage = UIImage.init(named: imageNamed+"_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        controller.title = title
//        设置标题的颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //        将控制器添加到导航控制器中,并将添加到tabbar中

        addChildViewController(UINavigationController.init(rootViewController: controller))
    }
}
